<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * Class CreateAddressesTable
 * 收货地址表
 */
class CreateAddressesTable extends Migration
{
    /**
     * 执行迁移
     */
    public function up()
    {
        Schema::create('addresses', function(Blueprint $table)
        {
            $table->increments('id');
            $table->string('name', 50);
            $table->unsignedInteger('third_level');
            $table->string('location', 100);
            $table->string('phone', 11);
            $table->string('postcode', 6);
            $table->boolean('default')->default(false);
            $table->unsignedInteger('user_id');
            $table->timestamps();
        });

        /**
         * 外键约束
         */
        Schema::table('addresses', function(Blueprint $table)
        {
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
    }

    /**
     * 迁移回滚
     */
    public function down()
    {
        Schema::drop('addresses');
    }
}
